<?php

class Zendhlt_View_Helper_OpensHoursElement extends Zend_View_Helper_FormElement {
	
    protected $html = '';
    
    public function opensHoursElement($name, $value = null, $attribs = null) {

        $helperSelect = new Zend_View_Helper_FormSelect();
        $helperSelect->setView($this->view);
        $helperText = new Zend_View_Helper_FormText();
        $helperText->setView($this->view);
        $helperHidden = new Zend_View_Helper_FormHidden();
        $helperHidden->setView($this->view);
        
    	$options = array('0' => 'Đóng cửa', '1' => 'Mở cửa');
    	$htmlHours = '';
    	$valSelect = 0;
    	$from = '';
    	$to = '';

    	$this->html .= "<ul>";
    
        if (isset($value['mo']['from'])) {
        	if (!empty($value['mo']['from'])) $from = date("H:i", strtotime($value['mo']['from']));
        	if (!empty($value['mo']['to'])) $to = date("H:i", strtotime($value['mo']['to']));
        	$valSelect = 1;
        	$htmlHours .= "<div class='text minWidth'>Từ</div>" . $helperText->formText($name . '[mo][from]', $from, array('id' => 'mo_form', 'class' => 'resHours'));
        	$htmlHours .= "<div class='text minWidth'>đến</div>" . $helperText->formText($name . '[mo][to]', $to, array('id' => 'mo_to', 'class' => 'resHours'));
        }
        $this->html .= "<li><div class='text'>Thứ 2</div>" . $helperSelect->formSelect($name . '[mo][optionDay]', $valSelect, array('id' => $name . '-mo', 'class' => 'birthday optionDay'), $options);
        $this->html .= "<div id='mo' class='hours'>" . $htmlHours . "</div><div class='clear'></div></li>";
        $this->html .= $helperHidden->formHidden($name . '[mo][day]', 'mo', array('class' => 'resHours'));
        
        $htmlHours = '';
        $valSelect = 0;
    	$from = '';
    	$to = '';
    	if (isset($value['tu']['from'])) {
        	if (!empty($value['tu']['from'])) $from = date("H:i", strtotime($value['tu']['from']));
        	if (!empty($value['tu']['to'])) $to = date("H:i", strtotime($value['tu']['to']));
        	$valSelect = 1;
        	$htmlHours .= "<div class='text minWidth'>Từ</div>" . $helperText->formText($name . '[tu][from]', $from, array('id' => 'tu_form', 'class' => 'resHours'));
        	$htmlHours .= "<div class='text minWidth'>đến</div>" . $helperText->formText($name . '[tu][to]', $to, array('id' => 'tu_to', 'class' => 'resHours'));
        }
        $this->html .= "<li><div class='text'>Thứ 3</div>" . $helperSelect->formSelect($name . '[tu][optionDay]', $valSelect, array('id' => $name . '-tu', 'class' => 'birthday optionDay'), $options);
        $this->html .= "<div id='tu' class='hours'>" . $htmlHours . "</div><div class='clear'></div></li>";
        $this->html .= $helperHidden->formHidden($name . '[tu][day]', 'tu', array('class' => 'resHours'));
        
    	$htmlHours = '';
    	$valSelect = 0;
    	$from = '';
    	$to = '';
    	if (isset($value['we']['from'])) {
        	if (!empty($value['we']['from'])) $from = date("H:i", strtotime($value['we']['from']));
        	if (!empty($value['we']['to'])) $to = date("H:i", strtotime($value['we']['to']));
        	$valSelect = 1;
        	$htmlHours .= "<div class='text minWidth'>Từ</div>" . $helperText->formText($name . '[we][from]', $from, array('id' => 'we_form', 'class' => 'resHours'));
        	$htmlHours .= "<div class='text minWidth'>đến</div>" . $helperText->formText($name . '[we][to]', $to, array('id' => 'we_to', 'class' => 'resHours'));
        }
        $this->html .= "<li><div class='text'>Thứ 4</div>" . $helperSelect->formSelect($name . '[we][optionDay]', $valSelect, array('id' => $name . '-we', 'class' => 'birthday optionDay'), $options);
        $this->html .= "<div id='we' class='hours'>" . $htmlHours . "</div><div class='clear'></div></li>";
        $this->html .= $helperHidden->formHidden($name . '[we][day]', 'we', array('class' => 'resHours'));
    	
    	$htmlHours = '';
    	$valSelect = 0;
    	$from = '';
    	$to = '';
    	if (isset($value['th']['from'])) {
        	if (!empty($value['th']['from'])) $from = date("H:i", strtotime($value['th']['from']));
        	if (!empty($value['th']['to'])) $to = date("H:i", strtotime($value['th']['to']));
        	$valSelect = 1;
        	$htmlHours .= "<div class='text minWidth'>Từ</div>" . $helperText->formText($name . '[th][from]', $from, array('id' => 'th_form', 'class' => 'resHours'));
        	$htmlHours .= "<div class='text minWidth'>đến</div>" . $helperText->formText($name . '[th][to]', $to, array('id' => 'th_to', 'class' => 'resHours'));
        }
        $this->html .= "<li><div class='text'>Thứ 5</div>" . $helperSelect->formSelect($name . '[th][optionDay]', $valSelect, array('id' => $name . '-th', 'class' => 'birthday optionDay'), $options);
        $this->html .= "<div id='th' class='hours'>" . $htmlHours . "</div><div class='clear'></div></li>";
        $this->html .= $helperHidden->formHidden($name . '[th][day]', 'th', array('class' => 'resHours'));
    	
    	$htmlHours = '';
    	$valSelect = 0;
    	$from = '';
    	$to = '';
    	if (isset($value['fr']['from'])) {
        	if (!empty($value['fr']['from'])) $from = date("H:i", strtotime($value['fr']['from']));
        	if (!empty($value['fr']['to'])) $to = date("H:i", strtotime($value['fr']['to']));
        	$valSelect = 1;
        	$htmlHours .= "<div class='text minWidth'>Từ</div>" . $helperText->formText($name . '[fr][from]', $from, array('id' => 'fr_form', 'class' => 'resHours'));
        	$htmlHours .= "<div class='text minWidth'>đến</div>" . $helperText->formText($name . '[fr][to]', $to, array('id' => 'fr_to', 'class' => 'resHours'));
        }
        $this->html .= "<li><div class='text'>Thứ 6</div>" . $helperSelect->formSelect($name . '[fr][optionDay]', $valSelect, array('id' => $name . '-fr', 'class' => 'birthday optionDay'), $options);
        $this->html .= "<div id='fr' class='hours'>" . $htmlHours . "</div><div class='clear'></div></li>";
        $this->html .= $helperHidden->formHidden($name . '[fr][day]', 'fr', array('class' => 'resHours'));
    	
    	$htmlHours = '';
    	$valSelect = 0;
    	$from = '';
    	$to = '';
    	if (isset($value['sa']['from'])) {
        	if (!empty($value['sa']['from'])) $from = date("H:i", strtotime($value['sa']['from']));
        	if (!empty($value['sa']['to'])) $to = date("H:i", strtotime($value['sa']['to']));
        	$valSelect = 1;
        	$htmlHours .= "<div class='text minWidth'>Từ</div>" . $helperText->formText($name . '[sa][from]', $from, array('id' => 'sa_form', 'class' => 'resHours'));
        	$htmlHours .= "<div class='text minWidth'>đến</div>" . $helperText->formText($name . '[sa][to]', $to, array('id' => 'sa_to', 'class' => 'resHours'));
        }
        $this->html .= "<li><div class='text'>Thứ 7</div>" . $helperSelect->formSelect($name . '[sa][optionDay]', $valSelect, array('id' => $name . '-sa', 'class' => 'birthday optionDay'), $options);
        $this->html .= "<div id='sa' class='hours'>" . $htmlHours . "</div><div class='clear'></div></li>";
        $this->html .= $helperHidden->formHidden($name . '[sa][day]', 'sa', array('class' => 'resHours'));
    	
    	$htmlHours = '';
    	$valSelect = 0;
    	$from = '';
    	$to = '';
    	if (isset($value['su']['from'])) {
        	if (!empty($value['su']['from'])) $from = date("H:i", strtotime($value['su']['from']));
        	if (!empty($value['su']['to'])) $to = date("H:i", strtotime($value['su']['to']));
        	$valSelect = 1;
        	$htmlHours .= "<div class='text minWidth'>Từ</div>" . $helperText->formText($name . '[su][from]', $from, array('id' => 'su_form', 'class' => 'resHours'));
        	$htmlHours .= "<div class='text minWidth'>đến</div>" . $helperText->formText($name . '[su][to]', $to, array('id' => 'su_to', 'class' => 'resHours'));
        }
        $this->html .= "<li><div class='text'>Chủ nhật</div>" . $helperSelect->formSelect($name . '[su][optionDay]', $valSelect, array('id' => $name . '-su', 'class' => 'birthday optionDay'), $options);
        $this->html .= "<div id='su' class='hours'>" . $htmlHours . "</div><div class='clear'></div></li>";
        $this->html .= $helperHidden->formHidden($name . '[su][day]', 'su', array('class' => 'resHours'));
        $this->html .= "</ul>";
        
        return $this->html;
    }

}